package com.jml.shiro.test.utils;

import  org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

public class CyptographyUtils {

    /**
     *
     * base64加密
     * */
    public static String encBase64(String password){
        return Base64.encodeToString(password.getBytes());
    }

    /**
     *
     * base64解密
     * */
    public static String decBase64(String password){
        return Base64.decodeToString(password);
    }

    /**
     * MD5加密，salt增加了加密的复杂度,salt一般放在配置文件中读取。
     * */
    public static String md5(String password,String salt){
        return new Md5Hash(password,salt).toString();
    }


    public static void main(String[] args) {
        String pa="123456";
        String s = encBase64(pa);
        System.out.println(s);
        System.out.println(decBase64(s));
        System.out.println(md5(pa,"1"));
    }
}
